import 'package:flutter/material.dart';

/// Creates a image widget with shaded overlay.
class YJImageOverlay extends StatelessWidget {
  /// Creates a image widget with shaded overlay.
  const YJImageOverlay({
    Key? key,
    this.height,
    this.width,
    this.bgColor,
    this.padding,
    this.margin,
    this.image,
    this.child = const Text(''),
    this.alignment,
    this.borderRadius,
    this.colorFilter =
        const ColorFilter.mode(Colors.black26, BlendMode.colorBurn),
    this.boxFit = BoxFit.fill,
    this.border,
    this.shape = BoxShape.rectangle,
  }) : super(key: key);

  /// 高度
  final double? height;

  /// 宽度
  final double? width;

  /// 背景色
  final Color? bgColor;

  /// 外边距
  final EdgeInsetsGeometry? margin;

  /// 内边距
  final EdgeInsetsGeometry? padding;

  /// 可以为本地图片或网络图片，支持Gif格式图片
  final ImageProvider? image;

  /// 子组件
  final Widget child;

  /// 对齐方式
  final AlignmentGeometry? alignment;

  /// 图像显示样式
  final BoxFit? boxFit;

  /// 遮罩，示例：colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.5), BlendMode.darken) （黑色半透明遮罩）
  final ColorFilter? colorFilter;

  /// 圆角
  final BorderRadiusGeometry? borderRadius;

  /// 边框
  final Border? border;

  /// 图片形状，BoxShape.rectangle、BoxShape.circle
  final BoxShape shape;

  @override
  Widget build(BuildContext context) => Container(
        alignment: alignment,
        height: height,
        width: width ?? MediaQuery.of(context).size.width,
        margin: margin,
        padding: padding,
        child: child,
        decoration: BoxDecoration(
          shape: shape,
          borderRadius: borderRadius,
          border: border,
          color: bgColor,
          image: DecorationImage(
            fit: boxFit,
            colorFilter: colorFilter,
            image: image!,
          ),
        ),
      );
}
